package com.wuyou.dataStructure.tree;


/**
 * @Description 二叉树遍历
 * @Author yh.zhang
 * @Date 2023/11/30 11:06
 */
public class BinaryTreeErgodic {

    public static void main(String[] args) {
        int[] nums = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
        int height = 0;
        TreeNode head = null;
        TreeNode x = toTree(nums, head, 0, height);
//        System.out.println(x);
//        leftErgodic(x, 0);
    }


    public static TreeNode toTree(int[] nums, TreeNode head, int index, int height) {
        if (index >= nums.length) {
            return head;
        }
        head = new TreeNode(nums[index]);
        int leftChildIndex = 2 * index + 1;
        int rightChildIndex = 2 * index + 2;
        head.left = toTree(nums, head.left, leftChildIndex, height);
        head.right = toTree(nums, head.right, rightChildIndex, height);
        return head;
    }
    public static void leftErgodic(TreeNode head, int height) {
        if (head == null) {
            return;
        }
        System.out.println(head.val);
        leftErgodic(head.left, height);
        leftErgodic(head.right, height);
    }

    public void left(TreeNode left, int height) {
        if (left != null) {
            System.out.println("cur_left------" + left.val + "----height------" + height);
            if (left.left != null) {
                left(left.left, height++);
            }
            if (left.right != null) {
                right(left.right, height++);
            }
        }
    }

    public void right(TreeNode right, int height) {
        if (right != null) {
            System.out.println("cur_left------" + right.val + "----height------" + height);
            if (right.left != null) {
                left(right.left, height++);
            }
            if (right.right != null) {
                right(right.right, height++);
            }
        }
    }


}
